package com.module.sysconfig.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.module.sysconfig.entity.Bdck;
import com.module.sysconfig.service.BdckService;
import com.support.helper.AjaxHelper;
import com.support.util.StringUtils;
import com.support.web.ControllerSupport;
/**
 * 系统表单仓库
 */
@Controller
@Scope(value = "prototype")
@RequestMapping("/sysconfig/bdck")
public class BdckController extends ControllerSupport 
{
	 private final Logger logger = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private BdckService bdckService;
	
	/**
	 * 保存系统表单仓库数据
	 * @throws IOException
	 */
	@RequestMapping("/saveBdck")
	public void saveBdck() throws IOException
	{
		try
		{
			Map<String, String> paramsMap = this.getParamsMap();
			Bdck bdck = new Bdck();
			
			String BDMC = paramsMap.get("BDMC");
			String BDURL = paramsMap.get("BDURL");
			String BDBM = paramsMap.get("BDBM");
			String CJR = paramsMap.get("CJR");
			String CJRMC = paramsMap.get("CJRMC");
			String ZHXGR = paramsMap.get("ZHXGR");
			String ZHXGRMC = paramsMap.get("ZHXGRMC");
			String BZ1 = paramsMap.get("BZ1");
			String BZ2 = paramsMap.get("BZ2");
			String BZ3 = paramsMap.get("BZ3");
			String BZ4 = paramsMap.get("BZ4");
			
			
			bdck.setBdmc(BDMC == null ? "":BDMC);
			bdck.setBdurl(BDURL == null ? "":BDURL);
			bdck.setBdbm(BDBM == null ? "":BDBM);
			bdck.setCjr(CJR == null ? "":CJR);
			bdck.setCjrmc(CJRMC == null ? "":CJRMC);
			bdck.setZhxgr(ZHXGR == null ? "":ZHXGR);
			bdck.setZhxgrmc(ZHXGRMC == null ? "":ZHXGRMC);
			bdck.setSfhf(1);
			bdck.setBz1(BZ1 == null ? "":BZ1);
			bdck.setBz2(BZ2 == null ? "":BZ2);
			bdck.setBz3(BZ3 == null ? "":BZ3);
			bdck.setBz4(BZ4 == null ? "":BZ4);
			
			bdckService.saveBdck(bdck);
			
			returnJSONView(AjaxHelper.toJSON(bdck, AjaxHelper.SUCCESS, "表单仓库数据保存！"));
			
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BdckController.saveBdck:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 更新系统表单仓库数据
	 * @throws IOException
	 */
	@RequestMapping("/updateBdck")
	public void updateBdck() throws IOException
	{
		try
		{
			Map<String, String> paramsMap = this.getParamsMap();
			String id = paramsMap.get("ID");
			if(StringUtils.isEmpty(id))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, "缺少主键ID"));
				return;
			}
			Bdck bdck = bdckService.queryBdckById(Long.parseLong(id));//根据ID查询数据
			
			String BDMC = paramsMap.get("BDMC");
			String BDURL = paramsMap.get("BDURL");
			String BDBM = paramsMap.get("BDBM");
			String CJR = paramsMap.get("CJR");
			String CJRMC = paramsMap.get("CJRMC");
			String ZHXGR = paramsMap.get("ZHXGR");
			String ZHXGRMC = paramsMap.get("ZHXGRMC");
			String BZ1 = paramsMap.get("BZ1");
			String BZ2 = paramsMap.get("BZ2");
			String BZ3 = paramsMap.get("BZ3");
			String BZ4 = paramsMap.get("BZ4");
			
			bdck.setBdmc(BDMC == null ? bdck.getBdmc():BDMC);
			bdck.setBdurl(BDURL == null ? bdck.getBdurl():BDURL);
			bdck.setBdbm(BDBM == null ? bdck.getBdbm():BDBM);
			bdck.setCjr(CJR == null ? bdck.getCjr():CJR);
			bdck.setCjrmc(CJRMC == null ? bdck.getCjrmc():CJRMC);
			bdck.setZhxgr(ZHXGR == null ? bdck.getZhxgr():ZHXGR);
			bdck.setZhxgrmc(ZHXGRMC == null ? bdck.getZhxgrmc():ZHXGRMC);
			bdck.setBz1(BZ1 == null ? bdck.getBz1():BZ1);
			bdck.setBz2(BZ2 == null ? bdck.getBz2():BZ2);
			bdck.setBz3(BZ3 == null ? bdck.getBz3():BZ3);
			bdck.setBz4(BZ4 == null ? bdck.getBz4():BZ4);
			
			bdckService.updateBdck(bdck);
			
			returnJSONView(AjaxHelper.toJSON(bdck, AjaxHelper.SUCCESS, "表单仓库数据更新！"));
			
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BdckController.updateBdck:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 删除系统表单仓库数据
	 * @throws IOException
	 */
	@RequestMapping("/deleteBdck")
	public void deleteBdck() throws IOException
	{
		try
		{
			Map<String, String> paramsMap = this.getParamsMap();
			String id = paramsMap.get("ID");
			if(null == id)
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, "缺少主键ID"));
				return;
			}
			bdckService.deleteBdck(Long.parseLong(id));
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "删除表单仓库数据！"));
			
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BdckController.deleteBdck:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 查询系统表单仓库所有数据
	 * @throws IOException
	 */
	@RequestMapping("/queryBdckRecord")
	public void queryBdckRecord() throws IOException
	{
		try
		{
			
			List<Map<String, Object>> bdckList = bdckService.queryBdckRecord();
			returnJSONView(AjaxHelper.toJSON(bdckList, AjaxHelper.SUCCESS, "表单仓库数据查询！"));
			
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BdckController.queryBdckRecord:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
}
